#include "vector.h"
#include <cmath>	// sqrt

void VectorSet (Vector3 a, float x, float y, float z)
{
	a[0] = x;
	a[1] = y;
	a[2] = z;
}

void VectorCopy (Vector3 from, Vector3 to)
{
	to[0] = from[0];
	to[1] = from[1];
	to[2] = from[2];
}

void VectorAdd (Vector3 a, Vector3 b, Vector3 out)
{
	out[0] = a[0] + b[0];
	out[1] = a[1] + b[1];
	out[2] = a[2] + b[2];
}

void VectorSubtract (Vector3 a, Vector3 b, Vector3 out)
{
	out[0] = a[0] - b[0];
	out[1] = a[1] - b[1];
	out[2] = a[2] - b[2];
}

float DotProduct (Vector3 a, Vector3 b)
{
	return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
}

float VectorSize (Vector3 in)
{
	return sqrt(in[0]*in[0] + in[1]*in[1] + in[2]*in[2]);
}

void Normalize (Vector3 in)
{
	float size = VectorSize(in);
	if (size != 0) // prevent divide-by-zero
	{
		in[0] /= size;
		in[1] /= size;
		in[2] /= size;
	}
}
